package com.wc.算法提高课.D第四章_高级数据结构.Floyd算法.牛的旅行;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/14 15:45
 * @description https://www.acwing.com/problem/content/description/1127/
 */
public class Main {
    /**
     * 思路：<p>
     * floyd 计算每两个牧场之间的最短距离<p>
     * 这个最大直径选择的方式: max{dist[i][j]}<p>
     * 经过增加连接的边-> maxd[i] + dist[i][j] + maxd[j]<p>
     * maxd[i]表示距离i最远的点的距离
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 155;
    static double INF = 1e20;
    static char[][] g = new char[N][];
    static double[][] dist = new double[N][N], q = new double[N][2];
    static double[] maxd = new double[N];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            q[i][0] = sc.nextInt();
            q[i][1] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) g[i] = sc.next().toCharArray();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i != j) {
                    if (g[i][j] == '1') dist[i][j] = getDist(q[i], q[j]);
                    else dist[i][j] = INF;
                }
            }
        }
        for (int k = 0; k < n; k++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    dist[i][j] = Math.min(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }
        double res1 = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (dist[i][j] != INF) maxd[i] = Math.max(maxd[i], dist[i][j]);
            }
            res1 = Math.max(res1, maxd[i]);
        }

        double res2 = INF;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (dist[i][j] == INF) res2 = Math.min(res2, maxd[i] + getDist(q[i], q[j]) + maxd[j]);
            }
        }
        out.printf("%.6f\n", Math.max(res1, res2));
        out.flush();
    }

    static double getDist(double[] a, double[] b) {
        double dx = a[0] - b[0], dy = a[1] - b[1];
        return Math.sqrt(dx * dx + dy * dy);
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
